package cn.com.zhuxulin.info.Services;

import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;

import cn.com.zhuxulin.info.Interfaces.Parse;
import cn.com.zhuxulin.info.Utils.HttpRequest;
import cn.com.zhuxulin.info.Utils.IOUtils;
import cn.com.zhuxulin.info.Utils.ReplaceXml;

public class MobileInfo implements Parse{
	private static String url = "http://webservice.webxml.com.cn/WebServices/MobileCodeWS.asmx";
	private static String xmlFileName = "/mobile.xml";
	private static String xml;
	public String parse(String xml) {
		return xml.substring(xml.indexOf("<getMobileCodeInfoResult>") + "<getMobileCodeInfoResult>".length(), xml.indexOf("</getMobileCodeInfoResult>"));
	}
	public void setMobileNumber(String number) throws UnsupportedEncodingException, IOException{
		InputStream inputStream=this.getClass().getResourceAsStream(xmlFileName);
		xml=ReplaceXml.replace(IOUtils.getXmlString(inputStream),"mobileNumber", number);
	}
	public String getMobileNumberLocation() throws Exception{
		return parse(HttpRequest.doPost(url, xml));
	}
}
